// pages/doctorPages/order/order.js
var app = getApp();
const ajax = require("../../../utils/ajax.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderList: [],
    tabList: [{
      name: "全部",
      status: ""
    }, {
      name: "失约",
      status: 3
    }, {
      name: "待支付",
      status: 0
    }, {
      name: "取消",
      status: 4
    }, {
      name: "已就座",
      status: 2
    }, {
      name: "待就座",
      status: 1
    }],
    status: "",
    num:1,
    pageSize:0
  },
  tabClick: function(e) {
    let status = e.currentTarget.dataset.status
    this.setData({
      status: status,
      orderList: [],
      num:1
    })
    this.getData(1,this.data.status)
  },
  orderDetail: function(e) {
    wx.navigateTo({
      url: '/pages/userPages/history/orderDetail/orderDetail?id=' + e.currentTarget.dataset.id + "&type=doctor&status=" + e.currentTarget.dataset.status
    })
  },
  getData: function(num, status) {
    wx.showLoading({
      title: '拼命加载中',
    })
    ajax.request({
      url: app.url.appointments,
      data: {
        status: status,
        page:num
      }
    }).then(res => {
      if (res.code == 200) {
        this.setData({
          orderList: this.data.orderList.concat(res.data.data),
          pageSize: res.data.pages.pageSize
        })
        wx.hideLoading()
      }else{
        return wx.showToast({
          title: res.msg,
          icon:"none"
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    app.globalData.template.tabbar("tabBar", 1, this) //0表示第一个tabbar
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.setData({
      orderList: []
    })
    this.getData(1,'');
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.setData({
      num: this.data.num + 1
    })
    if(this.data.pageSize<this.data.num){
      return 
    }
    this.getData(this.data.num, this.data.status)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})